package com.intelligentclass.services;

import com.intelligentclass.entity.Courseware;
import com.intelligentclass.entity.Exercise;
import com.intelligentclass.entity.Historypaper;
import com.intelligentclass.repositories.ExerciseRespository;
import com.intelligentclass.repositories.HistorypaperRespository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HistorypaperService {

    private final ExerciseService exerciseService;
    private final ExerciseRespository exerciseRespository;
    private HistorypaperRespository historypaperRespository;

    public HistorypaperService(HistorypaperRespository historypaperRespository, ExerciseService exerciseService, ExerciseRespository exerciseRespository) {
        this.historypaperRespository = historypaperRespository;
        this.exerciseService = exerciseService;
        this.exerciseRespository = exerciseRespository;
    }

    public List<Historypaper> getAllHistorypaperByCid(int cid) {
        List<Historypaper> list = historypaperRespository.findAllByCid(cid);
        if(!list.isEmpty()) {
            return list;
        }
        else{
            return null;
        }
    }

    public Historypaper getHistorypaperById(int id) {
        return historypaperRespository.findById(id).orElse(null);
    }
    public Historypaper save(Historypaper historypaper) {
        return historypaperRespository.save(historypaper);
    }
    public Historypaper getHistoryPaperByCidAndName(int cid, String name){

        Historypaper hp =  historypaperRespository.findByCidAndName(cid, name);
        return hp;
    }

    public Historypaper getHistorypaper(int cid, String name, int parent){
        return historypaperRespository.find(cid, name, parent);
    }
}
